# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Carlo Landmeter <clandmeter@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=dropbear
pkgver=2020.80
pkgrel=0
pkgdesc="small SSH 2 client/server designed for small memory environments"
url="https://matt.ucc.asn.au/dropbear/dropbear.html"
arch="all"
license="MIT"
options="!check"
makedepends="zlib-dev linux-headers"
subpackages="$pkgname-doc
	$pkgname-openrc
	$pkgname-convert:_convert
	$pkgname-dbclient:_dbclient
	$pkgname-ssh:_ssh:noarch
	$pkgname-scp:_scp"
source="https://matt.ucc.asn.au/dropbear/releases/dropbear-$pkgver.tar.bz2
	dropbear.initd
	dropbear.confd
	dropbear-0.53.1-static_build_fix.patch
	dropbear-options_sftp-server_path.patch
	"

# secfixes:
#   2020.79-r0:
#     - CVE-2018-20685
#   2018.76-r2:
#     - CVE-2018-15599

_progs="dropbear dropbearkey dbclient dropbearconvert scp"

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--disable-wtmp \
		--disable-lastlog
	make PROGRAMS="$_progs"
}

package() {
	make PROGRAMS="$_progs" DESTDIR="$pkgdir" install

	install -D -m755 "$srcdir"/dropbear.initd \
		"$pkgdir"/etc/init.d/dropbear
	install -D -m644 "$srcdir"/dropbear.confd \
		"$pkgdir"/etc/conf.d/dropbear
}

_convert() {
	pkgdesc="$pkgname dropbearconvert command"
	depends=""
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/dropbearconvert "$subpkgdir"/usr/bin/
}

_dbclient() {
	pkgdesc="$pkgname dbclient command"
	depends=""
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/dbclient "$subpkgdir"/usr/bin/
}

_scp() {
	pkgdesc="$pkgname scp support"
	depends="!openssh-client"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/scp "$subpkgdir"/usr/bin/
}

_ssh() {
	pkgdesc="$pkgname ssh command (compatibility symlink for dbclient)"
	depends="dropbear-dbclient !openssh-client"
	mkdir -p "$subpkgdir"/usr/bin
	ln -s /usr/bin/dbclient "$subpkgdir"/usr/bin/ssh
}

sha512sums="7fccc1003b73540fa1da9763771519f8ae52608f7a1c5f66736db1885a87c346bd9711bcf017c48ba712a83ff04f01c12bea7180ed596fe58038fe656d2fd3d3  dropbear-2020.80.tar.bz2
9c55ab3d8b61955cde1ccc1b8acbd3d2ef123feb9489e92737304c35315d07b7f85fad8a12ac7b0ec2c1dcee3d76b8bc4aa18518f4ddd963917805db33e48826  dropbear.initd
83f2c1eaf7687917a4b2bae7d599d4378c4bd64f9126ba42fc5d235f2b3c9a474d1b3168d70ed64bb4101cc251d30bc9ae20604da9b5d819fcd635ee4d0ebb0f  dropbear.confd
413cef467db35ddc430a773af943ff650d51bdb6fb262dcabc625eb6c9f4170b5711998df5577dd05c60e21e0a9771bff022adc8273083b85a18f4d5659ffd50  dropbear-0.53.1-static_build_fix.patch
9b078548c6850c9b45e9b68a8ebd746a4a0648607c8ad0cf4106f09f7a63768c83a3e4e4fbec38b665ae283503fd3cdd054775aa3c9afe02567be3e775aef50b  dropbear-options_sftp-server_path.patch"
